package server.model.region;

import java.util.Collection;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;

import server.model.npcs.NPC;
import server.model.players.Client;

/**
 * Represents a single region.
 * @author Jinrake
 *
 */
public class Region {

	/**
	 * The region coordinates.
	 */
	private RegionCoordinates coordinate;
	
	/**
	 * A list of Clients in this region.
	 */
	private List<Client> Clients = new LinkedList<Client>();
	
	/**
	 * A list of NPCs in this region.
	 */
	private List<NPC> npcs = new LinkedList<NPC>();	
	
	/**
	 * Creates a region.
	 * @param coordinate The coordinate.
	 */
	public Region(RegionCoordinates coordinate) {
		this.coordinate = coordinate;
	}
	
	/**
	 * Gets the region coordinates.
	 * @return The region coordinates.
	 */
	public RegionCoordinates getCoordinates() {
		return coordinate;
	}

	/**
	 * Gets the list of Clients.
	 * @return The list of Clients.
	 */
	public Collection<Client> getClients() {
		synchronized(this) {
			return Collections.unmodifiableCollection(new LinkedList<Client>(Clients));
		}
	}
	
	/**
	 * Gets the list of NPCs.
	 * @return The list of NPCs.
	 */
	public Collection<NPC> getNpcs() {
		synchronized(this) {
			return Collections.unmodifiableCollection(new LinkedList<NPC>(npcs));
		}
	}
	
	/**
	 * Adds a new Client.
	 * @param Client The Client to add.
	 */
	public void addClient(Client Client) {
		synchronized(this) {
			Clients.add(Client);
			//entities.add(Client);
		}
	}

	/**
	 * Removes an old Client.
	 * @param Client The Client to remove.
	 */
	public void removeClient(Client Client) {
		synchronized(this) {
			Clients.remove(Client);
			//entities.remove(Client);
		}
	}

	/**
	 * Adds a new NPC.
	 * @param npc The NPC to add.
	 */
	public void addNpc(NPC npc) {
		synchronized(this) {
			npcs.add(npc);
			//entities.add(npc);
		}
	}

	/**
	 * Removes an old NPC.
	 * @param npc The NPC to remove.
	 */
	public void removeNpc(NPC npc) {
		synchronized(this) {
			npcs.remove(npc);
			//entities.remove(npc);
		}
	}
}
